-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQL-2288: Create mongosqltranslate integration tests #251
base: on-prem-eap
Are you sure you want to change the base?
Conversation
…b#245) * cargo.lock * handle enterprise mode in get_next_metadata()
let command = CheckDriverVersion::new(DRIVER_ODBC_VERSION.clone()); | ||
let command = CheckDriverVersion::new(DRIVER_METRICS_VERSION.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DRIVER_ODBC_VERSION
wasn't a valid semver version, so I switched to the DRIVER_METRICS_VERSION
.
|
||
let current_col_metadata_response: ResultSetSchema = if mongo_connection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code was merged into master with SQL-2374
#[serde(tag = "command_type")] | ||
pub enum CommandResponse { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deserialization wasn't working without this.
pub fn load_mongosqltranslate_library(mock_library: bool) { | ||
INIT.call_once(|| { | ||
let library_path = if cfg!(test) { | ||
let library_path = if mock_library { | ||
get_mock_library_path() | ||
} else { | ||
get_library_path(LIBRARY_NAME) | ||
get_library_path() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mock_library
is now only used by the unit test in this file; all the other tests can use the real library now, so I figured we could do this instead to make things easier.
/// | ||
/// NOTE: FLAKY TEST |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I was testing, I noticed sometimes this test would fail, so I'm guessing it's flaky. Has anyone else noticed this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I haven't noticed it. What was the error it was reporting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can see in this patch that it failed. I'm not sure what the error is, but the exit code is 101, so I'm guessing something panicked.
Additionally, I just remembered, once I commented out that test and ran another patch, some other tests started failing with exit code 101. You can see in this patch. However, this is the only time these tests failed. Also, later on when I uncommented the test_type_listing
test, it worked fine.
So I'm not really sure what's going on.
#[test] | ||
fn test_srv_style_uri_connection() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test requires libmongosqltranslate, so I moved it here to make testing easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of good work. I had some suggestions.
core/src/databases.rs
Outdated
@@ -221,7 +221,13 @@ impl MongoDatabases { | |||
}) | |||
.unwrap() | |||
.iter() | |||
.filter(|&db_name| !db_name.is_empty() && !db_name.eq("admin")) | |||
.filter(|&db_name| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this list of databases and filter is in a couple places, can we add a helper function to filter out the databases we don't want?
core/src/fields.rs
Outdated
if let Err(error) = result_set_schema { | ||
// If there is an Error while deserializing the schema, we won't show any columns for it | ||
warnings.push(error); | ||
continue; | ||
} | ||
|
||
result_set_schema.unwrap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about something like this to avoid the unwrap, it has similar behavior:
match result_set_schema {
Ok(schema) => schema,
Err(error) => {
warnings.push(error);
continue;
}
}
/// | ||
/// NOTE: FLAKY TEST |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I haven't noticed it. What was the error it was reporting?
query.push(0); | ||
|
||
assert_eq!( | ||
SqlReturn::ERROR, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to add a check for what error we're getting here. If this one is SchemaDocumentNotFoundInSchemaCollection
then it would be something like:
let error_message = get_sql_diagnostics(HandleType::SQL_HANDLE_STMT, stmt as Handle);
assert!(
error_message.contains("The following collection(s) were not found in the `__sql_schemas` collection"),
"Expected error message about missing schema collection, got: {}",
error_message
);
```
query.push(0); | ||
|
||
assert_eq!( | ||
SqlReturn::ERROR, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here to confirm what error we get.
db.run_command(get_schema_cmd).await.unwrap(), | ||
) | ||
.map_err(|e| { | ||
Error::CollectionDeserialization(collection_name.clone(), e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about an integration test that confirms we get this on a deserialization error?
} | ||
let _ = unsafe { Box::from_raw(env_handle) }; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One test I see in the design document that I don't see implemented yet is Invalid Command
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Invalid Command
tests ended up being unit tests in mongosqltranslate
. Since we control the API and the driver's calls to the API, I don't think it's possible to have an integration test that has an invalid command.
// Struct representing the ResultSetSchema. | ||
// The `schema` field needs the alias `result_set_schema` because this struct is used to get the schema | ||
// from the __sql_schemas collection, which stores the schema in it's `schema` field, and the libmongosqltranslate | ||
// `translate` command, which stores the schema in it's `result_set_schema` field. | ||
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone, Default)] | ||
pub struct ResultSetSchema { | ||
#[serde(rename = "result_set_schema")] | ||
#[serde(alias = "result_set_schema")] | ||
pub schema: crate::json_schema::Schema, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why this wasn't failing earlier, but I fixed it and added a comment explaining what's going on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh actually I think it's because the error it would cause gets pushed into a warnings
vector instead of causing a crash. This is probably why my tests weren't failing.
let result_set_schema: Result<ResultSetSchema> =
ResultSetSchema::from_sql_schemas_document(&schema_doc).map_err(
|e| {
Error::CollectionDeserialization(collection_name.clone(), e)
},
);
match result_set_schema {
Ok(result_set_schema) => result_set_schema,
Err(error) => {
// If there is an Error while deserializing the schema, we won't show any columns for it
warnings.push(error);
continue;
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wait never mind. The part of the code that would fail was never called by my tests. That's why this wasn't causing any failures.
This PR corrects the changes made in SQL-2291 and adds integration tests.
The path for libmongosqltranslate will instead be modified in this follow up ticket: https://jira.mongodb.org/browse/SQL-2403
Evergreen patch with everything passing: https://spruce.mongodb.com/version/670ee37a1d7c8900078da0ec/tasks?page=0&sorts=STATUS%3AASC%3BBASE_STATUS%3ADESC&statuses=success&variant=%5Eubuntu2204%24